package com.application.fabric.test;

import com.application.fabric.fabriccontrol.existevidence.getcacert;
import com.application.fabric.fabriccontrol.fabricinit.Initaccount;
import com.application.fabric.fabriccontrol.operate.entityfabric.BasicAsset;
import com.application.fabric.fabriccontrol.operate.serverfabric.ServeAsset;
import com.application.fabric.test.Token.Token01;
import com.application.fabric.test.pathchangetest.changepath;
//import com.auth0.jwt.interfaces.DecodedJWT;
import com.itextpdf.text.Document;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfWriter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.FileOutputStream;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/test")
public class packageclass {


    @Autowired
    private Initaccount initaccount;
    /*初始化管道*/
    @PostMapping("t")
    public Map<String,Object> LoginUsers() throws Exception{

//        init.Test();
        initaccount.Initmain();

        Map<String,Object> map = new HashMap<>();
        map.put("code",200);
        map.put("msg","验证成功");
        map.put("verify","1");
        return map;
    }

    /*
    * 初始化路径*/
    @Autowired
    private changepath change;
    @PostMapping("init")
    public Map<String,Object> Initpath() throws Exception{

//        init.Test();
        change.changemain();
        Map<String,Object> map = new HashMap<>();
        map.put("code",200);
        map.put("msg","验证成功");
        map.put("verify","1");
        return map;
    }

    @Autowired
    private ServeAsset serveAsset;

    @PostMapping("operate")
    public Map<String,Object> operateasset() throws Exception{
//        serveAsset.InitLedger();
//        serveAsset.Queryallasset();
//        serveAsset.Queryassetbyid("asset11");
//        serveAsset.Knowexit("asset11");
//        serveAsset.Deleteasset("asset11");
//        serveAsset.Knowexit("asset11");

         BasicAsset basicAsset = new BasicAsset();
         basicAsset.setId("asset16");
         basicAsset.setOwner("cjb");
         basicAsset.setName("122");
//         basicAsset.setColor("黄");
         basicAsset.setAppraisedvalue("3000");

         serveAsset.Submitallasset(basicAsset);
//        serveAsset.Queryallasset();


//        serveAsset.MoveAllasset("asset11","lys");
//        serveAsset.Queryallasset();
//          serveAsset.Queryallasset();
//          serveAsset.Partasset("黄","Tomoko");
//          serveAsset.Queryallasset();

        /*没有*/
//        serveAsset.QueryAssetsByOwner("lys1");
//        serveAsset.Queryallasset();

        /*也没有*/
//        serveAsset.Gethistorydata("asset11");
        Map<String,Object> map = new HashMap<>();
        map.put("code",200);
        map.put("msg","验证成功");
        map.put("verify","1");
        return map;
    }

    /*存证获取测试*/
    @Autowired
    private getcacert  getcacert;
    @PostMapping("getcerm")
    public Map<String,Object> getcerm() throws Exception{

//        String str = getcacert.getcermsd5Id();
//        String str = getcacert.getuserPrikey();
        String str = getcacert.cacermbase64();
        Map<String,Object> map = new HashMap<>();
        map.put("code",200);
        map.put("msg","验证成功");
        map.put("verify",str);
        return map;
    }

    @PostMapping("pfdtest")
    public  PdfWriter pfdtest() throws Exception{


        // 创建一个Document对象
        Document document = new Document();

        // 创建PdfWriter对象，并将Document与输出流关联
        PdfWriter t =PdfWriter.getInstance(document, new FileOutputStream("example.pdf"));

        // 打开Document对象
        document.open();

        // 向Document中添加内容
        document.add(new Paragraph("Hello, World!"));
        // 关闭Document对象
        document.close();
        return t;
    }



//    /*token验证测试*/
//    Token01 token = new Token01();
//    Map<String,String> map = new HashMap<>();
//    @PostMapping("tokentest")
//    public String getToken(){
//        Token01 token = new Token01();
//        Map<String,String> map = new HashMap<>();
//        map.put("ceshi01","ceshi01");
//        return   token.getToken(map);
//    }
//
//    @PostMapping("tokenver")
//    public DecodedJWT verToken(String token1){
//         return token.verify(token1);
//    }

}
